package cn.tedu.spring.resource;

import cn.tedu.spring.config.SpringConfig;
import cn.tedu.spring.resource.controller.ReController;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestResource {

    // 1.使用xml方式开启组件扫描
    @Test
    public void testRe(){
        // 加载xml配置文件，开启组件扫描(<context:component-scan ...>)
        ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
        ReController controller = context.getBean(ReController.class);
        // 调用类方法进行测试
        controller.cont();
    }

    // 使用配置类开启组件扫描
    @Test
    public void configTest(){
        // 加载配置类
        ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        // 获取bean对象
        ReController controller = context.getBean(ReController.class);
        // 调用方法测试
        controller.cont();
    }
}








